package com.darrenchan.spark.hive;

import org.apache.hadoop.hive.ql.exec.UDF;

public class MyMin extends UDF {
    public String evaluate(String str) {
        String[] strs = str.split(",");
        int min = Integer.MAX_VALUE;
        String res = null;
        for (int i = 0; i < strs.length; i++) {
            if("null".equals(strs[i].split("_")[0])) continue;
            if(Integer.parseInt(strs[i].split("_")[0]) < min) {
                min = Integer.parseInt(strs[i].split("_")[0]);
            }
        }
        for (int i = 0; i < strs.length; i++) {
            if("null".equals(strs[i].split("_")[0])) continue;
            if(Integer.parseInt(strs[i].split("_")[0]) == min) {
                res = strs[i].split("_")[0];
                break;
            }
        }
        return res;
    }
}
